package com.haoze.nurse.controller;

import com.alibaba.fastjson.JSONObject;
import com.haoze.common.response.Result;
import com.haoze.common.response.ResultGenerator;
import com.haoze.nurse.dto.PatientCardsDTO;
import com.haoze.nurse.service.NursePatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/nurse/patient")
@Validated
@Api(value = "护理病人信息")
public class NursePatientController {

    @Resource
    NursePatientService nursePatientService;

    @GetMapping("/depts")
    @ApiOperation(value = "获取授权科室或病区")
    public Result getDepts() {
        return nursePatientService.getDepts();
    }

    @GetMapping("/nursePatients")
    @ApiOperation(value = "获取指定病区病员列表")
    public Result getNursePatients(@RequestParam final String wardId,
                                   @RequestParam(required = false, defaultValue = "0") String status,
                                   @RequestParam(required = false) String search) {
        return nursePatientService.getNursePatients(wardId, search, status);
    }

    @GetMapping("/nursePatients2")
    @ApiOperation(value = "获取指定病区病员列表")
    public Result getNursePatients(@RequestParam final String wardId,
                                   @RequestParam(required = false, defaultValue = "0") String status,
                                   @RequestParam(required = false) String search,
                                   @RequestParam(required = false, defaultValue = "1") int page,
                                   @RequestParam(required = false, defaultValue = "20") int pageSize) {
        return nursePatientService.getNursePatients2(wardId, search, status,page,pageSize);
    }

    @GetMapping("/patientInfo")
    @ApiOperation(value = "获取病人信息")
    public Result getPatientMsg(@RequestParam final String inpatNum,@RequestParam(defaultValue = "false") final boolean isHide) {
        return nursePatientService.getPatientMsg(inpatNum,isHide);
    }

    @GetMapping("/searchDiags")
    @ApiOperation(value = "通过关键字搜索诊断")
    public Result searchDiags(@RequestParam final String diag) {
        List<Map<String, String>> diagList = nursePatientService.searchDiags(diag);
        return ResultGenerator.genOkResult(diagList);
    }

    @GetMapping("/bondDiag")
    @ApiOperation(value = "绑定诊断到文书")
    public Result bondDiag(@RequestParam final String diagId,
                           @RequestParam final String inpatNum) {
        Result result = nursePatientService.bondDiag(diagId, inpatNum);
        return result;
    }

    @GetMapping("/bondGestationInfo")
    @ApiOperation(value = "绑定妊娠信息")
    public Result bondGestationInfo(@RequestParam String inpatNum,
                                    @RequestParam(required = false, defaultValue = "") String pregnancyCount,
                                    @RequestParam(required = false, defaultValue = "") String productionCount,
                                    @RequestParam(required = false, defaultValue = "") String expectedDate) {
        return nursePatientService.bondGestationInfo(inpatNum, pregnancyCount, productionCount, expectedDate);
    }

    @GetMapping("/getLMP")
    @ApiOperation(value = "获取末次月经时间")
    public Result getLMP(@RequestParam final String inpatNum) {
        return nursePatientService.getLMP(inpatNum);
    }

    @GetMapping("/getBabyNum")
    @ApiOperation(value = "获取婴儿数量")
    public Result getBabyNum(@RequestParam final String inpatNum) {
        return nursePatientService.getBabyNum(inpatNum);
    }


    @PostMapping("/patientInfoCards")
    @ApiOperation(value = "获取指定病区病人信息卡")
    public Result getNursePatients(@RequestBody final PatientCardsDTO cardsDTO) {
        return nursePatientService.getPatientInfoCards(cardsDTO);
    }

    @GetMapping("/healthNum")
    @ApiOperation(value = "获取健康号")
    public Result getHealthNum(@RequestParam final String inpatNum) {
        return nursePatientService.getHealthNum(inpatNum);
    }

    @GetMapping("/getPatientInfo")
    @ApiOperation(value = "获取病人信息（病区病人用）")
    public Result getPatientInfo(@RequestParam final String wardDeptId, @RequestParam final String medicalNum, @RequestParam final String bedNo) {
        return nursePatientService.getPatientInfo(wardDeptId, medicalNum, bedNo);
    }

    @GetMapping("/getWardOverviewNumByWardId")
    @ApiOperation(value = "获取病区总览对应的人数")
    public Result getWardOverviewNumByWardId(@RequestParam final String wardDeptId) {
        return nursePatientService.getWardOverviewNumByWardId(wardDeptId);
    }


    @GetMapping("/dischargedSettle")
    @ApiOperation(value = "出院病人结算情况")
    public Result dischargedSettle(@RequestParam String wardDeptId, @RequestParam String beginTime, @RequestParam String endTime, @RequestParam(required = false) String queryString, @RequestParam(defaultValue = "1") String type,@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "20")int pageSize) {
        return nursePatientService.dischargedSettle(wardDeptId, beginTime, endTime, queryString, type,page,pageSize);
    }


    @GetMapping("/handNumbness")
    @ApiOperation(value = "判断是否为手术室还是普通科室")
    public Result handNumbness(@RequestParam String wardDeptId){
        return nursePatientService.handNumbness(wardDeptId);
    }


    @GetMapping("/querySpecialWard")
    @ApiOperation(value = "获取产科或者新生儿科的病区数据")
    public Result querySpecialWard(@RequestParam(required = false) String wardId,@RequestParam(required = false) String varCode){
        return nursePatientService.querySpecialWard(wardId,varCode);
    }

}
